<template>
  <div class="my-data">
    <NavBar :title="title" />
    <div class="content-top">
      <MyEmpty v-if="loading === false && list.length === 0" />
      <van-list v-model="loading" :finished="true" finished-text="没有更多了" @load="onLoad" v-else>
        <van-swipe-cell class="list-item" v-for="(item, index) in list" :key="index">
          <div class="item-show" @click="onItemClick(item)">
            <p>
              <span>{{ item.StationName }}</span>
              <span>{{ item.InterviewDateStr }}</span>
            </p>
            <p>
              <span>{{ item.CompanyName }}</span>
              <span :class="{ 'unread': !item.IsRead }">{{ item.IsRead? '已读' : '未读'}}</span>
            </p>
          </div>
          <template #right>
            <van-button square text="删除" type="danger" style="height: 100%" @click="onDel(index, item.ID)" />
          </template>
        </van-swipe-cell>
      </van-list>
    </div>
  </div>
</template>

<script>
import NavBar from '@/components/NavBar.vue'
import MyEmpty from '@/components/MyEmpty.vue'
import { List, Toast, Dialog, SwipeCell, Button } from 'vant';
import { PersonDelInterwiewList } from '@/util/http'
import Global from '@/Global'
export default {
  name: 'InterView',
  components: { NavBar, MyEmpty, [List.name]: List, [SwipeCell.name]: SwipeCell, [Button.name]: Button, },
  props: ['title'],
  mounted() {
    this.onLoad();
  },
  // 定义属性
  data() {
    return {
      list: [],
      loading: true,
      finish: false
    }
  },
  // 方法集合
  methods: {
    onLoad() {
      this.loading = true;
      this.$api.get('/PAC/GetFaceNoticeListPerson').then(res => {
        this.loading = false;
        if (res.success) {
          this.list = [...this.list, ...res.response];
        }
      })
    },
    onItemClick(item) {
      this.$router.push({ name: 'person-interviewinfo', params: { id: item.ID } })
    },
    onDel(index, id) {
      Dialog.confirm({
        message: '确认删除该条记录？'
      }).then(() => {
        PersonDelInterwiewList(id).then(res => {
          Toast(res.msg)
          if (res.result === 1) {
            this.$bus.$emit(Global.bus_person_resume_update, "ok");
            this.list.splice(index, 1);
          }
        })
      }).catch(() => {
        // on cancel
      });
    }
  },
}
</script>

<style lang="less">
@import "vant/lib/dialog/index.less";
@import "@/assets/css/common.less";
@import "@/assets/css/person-my-job-list.css";
</style>